package com.xiyoukt.springboot.config;

import com.alibaba.druid.util.DruidPasswordCallback;
import com.xiyoukt.springboot.util.PasswdEncode;
import org.apache.commons.lang3.StringUtils;

import java.util.Properties;

public class DBPasswordCallback extends DruidPasswordCallback {

    // 密码加密解密的key
    private static final String PASSWORD_KEY = "xiyoukt_password";

    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        String password = properties.getProperty("password");
        if(StringUtils.isNotEmpty(password)){
            String decodePassword = PasswdEncode.aesDecode(password, PASSWORD_KEY);
            setPassword(decodePassword.toCharArray());
        }
    }
}
